package com.stream;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectDemo {
	public static void main(String[] args) {
		String str = "my name is 9527";
		//收集器
		List<String> list = Stream.of(str.split(" ")).collect(Collectors.toList());
		
		//String strS = Stream.of(str.split(" ")).reduce((s1,s2) -> s1+"|"+s2).orElse("");
		String strS = Stream.of(str.split(" ")).reduce("",(s1,s2) -> s1+"|"+s2);
		System.out.println(strS);
		
		//计算所有单词总长度
		Integer num = Stream.of(str.split(" ")).map(s->s.length()).reduce(0,(n1,n2)->n1+n2);
		System.out.println(num);
		
		String s = Stream.of(str.split(" ")).max((s1,s2)->s1.length()-s2.length()).orElse("");
		System.out.println(s);
	}
}
